package com.holyant.goods.enums;

import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**商品规格单位枚举
 * @author zgx
 * @Title:
 * @Package
 * @Description:
 * @date 2022/5/7 11:27
 */
public enum SpecificationUnitEnum {
    /** 毫升 */
    MILLILITER(10, "毫升"),
    /** 克 */
    GRAM(20, "克"),
    /** 片 */
    PIECE(30, "片"),
    /** 瓶 */
    BOTTLE(40, "瓶"),
    /** 袋 */
    BAG(50, "袋"),
    /** 毫克 */
    MILLIGRAM(60, "毫克"),
    /** 粒 */
    GRANULE(70, "粒"),
    /** 个 */
    INDIVIDUAL(80, "个"),
    /** 包 */
    PACKAGE(90, "包"),
    /** 双 */
    DOUBLE(100, "双"),
    /** 条 */
    STRIP(110, "条"),
    /** 只 */
    ONLY(120, "只"),
    /** 件 */
    APIECE(130, "件"),
    ;

    private final Integer code;
    private final String name;

    SpecificationUnitEnum(Integer code, String name)
    {
        this.code = code;
        this.name = name;
    }

    public Integer getCode()
    {
        return code;
    }

    public String getName()
    {
        return name;
    }


    public static Integer getCodeByName(String name) {
        for (SpecificationUnitEnum item : SpecificationUnitEnum.values()) {
            if (item.getName().equals(name)) {
                return item.code;
            }
        }
        return null;
    }



    public static String getNames() {
        return Arrays.stream(SpecificationUnitEnum.values()).map(SpecificationUnitEnum::getName).collect(Collectors.toList()).toString();
    }

    public static String getNameByCode(Integer code) {

        return Stream.of(SpecificationUnitEnum.values()).filter(s -> s.getCode().equals(code)).findFirst().map(SpecificationUnitEnum::getName).orElse(null);
    }
}
